package com.zhanghe.study.spring4.beans.tx;

import icu.zhhll.datasource.annotation.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zh
 * @date 2023/10/8 15:33
 */
@Service
public class MultiDataSourceService {

    @Autowired
    private UserDao userDao;

    @Autowired
    private MultiDataSourceService multiDataSourceService;

    @Transactional
    @DataSource(name = "data01")
    public void data(){
        System.out.println(userDao.findAccountById(1));
        multiDataSourceService.data02();

    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @DataSource(name = "data02")
    public void data02(){
        System.out.println(userDao.findAccountById(1));

    }
}
